<template>
  <div class="table-page-search-wrapper">
    <el-form ref="userForm" :model="queryParam" :inline="true" label-width="60px">
      <el-row :gutter="16">
        <el-col :span="4">
          <el-form-item label="工号" prop="username">
            <el-input
              clearable
              @keyup.native.enter="handleSearch"
              v-model="queryParam.username"
              placeholder="请输入工号搜索"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="名称" prop="name">
            <el-input
              @keyup.native.enter="handleSearch"
              v-model="queryParam.name"
              clearable
              placeholder="请输入用户名搜索"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="部门" prop="value">
            <dept-select
              :selectValue="queryParam.value"
              ref="deptSelect"
              @select="handleSelect"
              v-model="queryParam.value"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="状态" prop="state">
            <el-select v-model="queryParam.state" clearable placeholder="请选择">
              <el-option :value="0" label="正常"></el-option>
              <el-option :value="1" label="禁用"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item>
            <el-tooltip class="item" content="查询" effect="dark" placement="top">
              <el-button type="primary" class="mr5" icon="el-icon-search" @click="handleSearch" />
            </el-tooltip>
            <el-tooltip class="item" content="重置" effect="dark" placement="top">
              <el-button class="mr5" icon="el-icon-refresh-right" @click="handleReset" />
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item class="fr" style="margin-right: 0">
            <el-tooltip class="item" content="新增" effect="dark" placement="top">
              <el-button type="primary" icon="el-icon-plus" @click="$emit('add')" />
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getDeptTree } from '@/api/department'
import DeptSelect from '@/components/DeptSelect'

export default {
  name: 'UserForm',
  components: {
    DeptSelect
  },
  data() {
    return {
      // 查询参数
      queryParam: {
        name: null,
        deptId: null,
        state: 0,
        pageNo: 1
      }
    }
  },
  methods: {
    handleReset() {
      this.$refs.userForm.resetFields()
      this.$refs.deptSelect.reset()
      this.$set(this.queryParam, 'deptId', null)
      this.$emit('search', this.queryParam)
    },
    handleSelect(value) {
      console.log('value', value.id)
      this.$set(this.queryParam, 'deptId', value.id)
    },
    handleSearch() {
      this.$emit('search', this.queryParam)
    }
  }
}
</script>

<style scoped>
.el-card {
  overflow: inherit;
}
</style>
